package org.openit.portail.model;

import java.io.Serializable;
import java.util.Collections;
import java.util.Date;
import java.util.Map;
import java.util.WeakHashMap;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.proxy.HibernateProxy;


/** 
 * Object mapping for hibernate-handled table: parametre_client.
 * @author autogenerated
 */

@Entity
@Table(name = "parametre_client", catalog = "portail")
public class ParametreClient implements Cloneable, Serializable {

	/** Serial Version UID. */
	private static final long serialVersionUID = -559010015L;

	/** Use a WeakHashMap so entries will be garbage collected once all entities 
		referring to a saved hash are garbage collected themselves. */
	private static final Map<Serializable, Integer> SAVED_HASHES =
		Collections.synchronizedMap(new WeakHashMap<Serializable, Integer>());
	
	/** hashCode temporary storage. */
	private volatile Integer hashCode;
	

	/** Field mapping. */
	private Date dtCreation;
	/** Field mapping. */
	private Date dtModification;
	/** Field mapping. */
	private Integer id = 0; // init for hibernate bug workaround
	/** Field mapping. */
	private Client idClt;
	/** Field mapping. */
	private UserSystem idCreationUser;
	/** Field mapping. */
	private UserSystem idModificationUser;
	/** Field mapping. */
	private ParametreService idParamService;
	/** Field mapping. */
	private String parametreValeur;
	/**
	 * Default constructor, mainly for hibernate use.
	 */
	public ParametreClient() {
		// Default constructor
	} 

	/** Constructor taking a given ID.
	 * @param id to set
	 */
	public ParametreClient(Integer id) {
		this.id = id;
	}
	
 


 
	/** Return the type of this class. Useful for when dealing with proxies.
	* @return Defining class.
	*/
	@Transient
	public Class<?> getClassType() {
		return ParametreClient.class;
	}
 

    /**
     * Return the value associated with the column: dtCreation.
	 * @return A Date object (this.dtCreation)
	 */
	@Column( name = "dt_creation"  )
	public Date getDtCreation() {
		return this.dtCreation;
		
	}
	

  
    /**  
     * Set the value related to the column: dtCreation.
	 * @param dtCreation the dtCreation value you wish to set
	 */
	public void setDtCreation(final Date dtCreation) {
		this.dtCreation = dtCreation;
	}

    /**
     * Return the value associated with the column: dtModification.
	 * @return A Date object (this.dtModification)
	 */
	@Column( name = "dt_modification"  )
	public Date getDtModification() {
		return this.dtModification;
		
	}
	

  
    /**  
     * Set the value related to the column: dtModification.
	 * @param dtModification the dtModification value you wish to set
	 */
	public void setDtModification(final Date dtModification) {
		this.dtModification = dtModification;
	}

    /**
     * Return the value associated with the column: id.
	 * @return A Integer object (this.id)
	 */
    @Id 
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column( name = "id_param_clt", nullable = false  )
	public Integer getId() {
		return this.id;
		
	}
	

  
    /**  
     * Set the value related to the column: id.
	 * @param id the id value you wish to set
	 */
	public void setId(final Integer id) {
		// If we've just been persisted and hashCode has been
		// returned then make sure other entities with this
		// ID return the already returned hash code
		if ( (this.id == null || this.id == 0) &&
				(id != null) &&
				(this.hashCode != null) ) {
			SAVED_HASHES.put( id, this.hashCode );
		}
		this.id = id;
	}

    /**
     * Return the value associated with the column: idClt.
	 * @return A Client object (this.idClt)
	 */
	@ManyToOne( cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY )
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
	@JoinColumn(name = "Id_Clt", nullable = true )
	public Client getIdClt() {
		return this.idClt;
		
	}
	

  
    /**  
     * Set the value related to the column: idClt.
	 * @param idClt the idClt value you wish to set
	 */
	public void setIdClt(final Client idClt) {
		this.idClt = idClt;
	}

    /**
     * Return the value associated with the column: idCreationUser.
	 * @return A UserSystem object (this.idCreationUser)
	 */
	@ManyToOne( cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY )
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
	@JoinColumn(name = "Id_Creation_User", nullable = true )
	public UserSystem getIdCreationUser() {
		return this.idCreationUser;
		
	}
	

  
    /**  
     * Set the value related to the column: idCreationUser.
	 * @param idCreationUser the idCreationUser value you wish to set
	 */
	public void setIdCreationUser(final UserSystem idCreationUser) {
		this.idCreationUser = idCreationUser;
	}

    /**
     * Return the value associated with the column: idModificationUser.
	 * @return A UserSystem object (this.idModificationUser)
	 */
	@ManyToOne( cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY )
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
	@JoinColumn(name = "Id_Modification_User", nullable = true )
	public UserSystem getIdModificationUser() {
		return this.idModificationUser;
		
	}
	

  
    /**  
     * Set the value related to the column: idModificationUser.
	 * @param idModificationUser the idModificationUser value you wish to set
	 */
	public void setIdModificationUser(final UserSystem idModificationUser) {
		this.idModificationUser = idModificationUser;
	}

    /**
     * Return the value associated with the column: idParamService.
	 * @return A ParametreService object (this.idParamService)
	 */
	@ManyToOne( cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER )
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
	@JoinColumn(name = "Id_Param_Service", nullable = true )
	public ParametreService getIdParamService() {
		return this.idParamService;
		
	}
	

  
    /**  
     * Set the value related to the column: idParamService.
	 * @param idParamService the idParamService value you wish to set
	 */
	public void setIdParamService(final ParametreService idParamService) {
		this.idParamService = idParamService;
	}

    /**
     * Return the value associated with the column: parametreValeur.
	 * @return A String object (this.parametreValeur)
	 */
	@Column( name = "parametre_valeur", length = 30  )
	public String getParametreValeur() {
		return this.parametreValeur;
		
	}
	

  
    /**  
     * Set the value related to the column: parametreValeur.
	 * @param parametreValeur the parametreValeur value you wish to set
	 */
	public void setParametreValeur(final String parametreValeur) {
		this.parametreValeur = parametreValeur;
	}


   /**
    * Deep copy.
	* @return cloned object
	* @throws CloneNotSupportedException on error
    */
    @Override
    public ParametreClient clone() throws CloneNotSupportedException {
		
        final ParametreClient copy = (ParametreClient)super.clone();

		copy.setDtCreation(this.getDtCreation());
		copy.setDtModification(this.getDtModification());
		copy.setId(this.getId());
		copy.setIdClt(this.getIdClt());
		copy.setIdCreationUser(this.getIdCreationUser());
		copy.setIdModificationUser(this.getIdModificationUser());
		copy.setIdParamService(this.getIdParamService());
		copy.setParametreValeur(this.getParametreValeur());
		return copy;
	}
	


	/** Provides toString implementation.
	 * @see java.lang.Object#toString()
	 * @return String representation of this class.
	 */
	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		
		sb.append("dtCreation: " + this.getDtCreation() + ", ");
		sb.append("dtModification: " + this.getDtModification() + ", ");
		sb.append("id: " + this.getId() + ", ");
		sb.append("parametreValeur: " + this.getParametreValeur());
		return sb.toString();		
	}


	/** Equals implementation. 
	 * @see java.lang.Object#equals(java.lang.Object)
	 * @param aThat Object to compare with
	 * @return true/false
	 */
	@Override
	public boolean equals(final Object aThat) {
		Object proxyThat = aThat;
		
		if ( this == aThat ) {
			 return true;
		}

		
		if (aThat instanceof HibernateProxy) {
 			// narrow down the proxy to the class we are dealing with.
 			try {
				proxyThat = ((HibernateProxy) aThat).getHibernateLazyInitializer().getImplementation(); 
			} catch (org.hibernate.ObjectNotFoundException e) {
				return false;
		   	}
		}
		if (aThat == null)  {
			 return false;
		}
		
		final ParametreClient that; 
		try {
			that = (ParametreClient) proxyThat;
			if ( !(that.getClassType().equals(this.getClassType()))){
				return false;
			}
		} catch (org.hibernate.ObjectNotFoundException e) {
				return false;
		} catch (ClassCastException e) {
				return false;
		}
		
		
		boolean result = true;
		result = result && (((this.getId() == null) && ( that.getId() == null)) || (this.getId() != null  && this.getId().equals(that.getId())));
		result = result && (((getDtCreation() == null) && (that.getDtCreation() == null)) || (getDtCreation() != null && getDtCreation().equals(that.getDtCreation())));
		result = result && (((getDtModification() == null) && (that.getDtModification() == null)) || (getDtModification() != null && getDtModification().equals(that.getDtModification())));
		result = result && (((getIdClt() == null) && (that.getIdClt() == null)) || (getIdClt() != null && getIdClt().getId().equals(that.getIdClt().getId())));	
		result = result && (((getIdCreationUser() == null) && (that.getIdCreationUser() == null)) || (getIdCreationUser() != null && getIdCreationUser().getId().equals(that.getIdCreationUser().getId())));	
		result = result && (((getIdModificationUser() == null) && (that.getIdModificationUser() == null)) || (getIdModificationUser() != null && getIdModificationUser().getId().equals(that.getIdModificationUser().getId())));	
		result = result && (((getIdParamService() == null) && (that.getIdParamService() == null)) || (getIdParamService() != null && getIdParamService().getId().equals(that.getIdParamService().getId())));	
		result = result && (((getParametreValeur() == null) && (that.getParametreValeur() == null)) || (getParametreValeur() != null && getParametreValeur().equals(that.getParametreValeur())));
		return result;
	}
	
	/** Calculate the hashcode.
	 * @see java.lang.Object#hashCode()
	 * @return a calculated number
	 */
	@Override
	public int hashCode() {
		if ( this.hashCode == null ) {
			synchronized ( this ) {
				if ( this.hashCode == null ) {
					Integer newHashCode = null;

					if ( getId() != null ) {
						newHashCode = SAVED_HASHES.get( getId() );
					}
					
					if ( newHashCode == null ) {
						if ( getId() != null && getId() != 0) {
							newHashCode = getId();
						} else {
							newHashCode = super.hashCode();

						}
					}
					
					this.hashCode = newHashCode;
				}
			}
		}
	return this.hashCode;
	}
	

	
}
